<template>
  <div class="New_build">
    <!-- 这个只是充当遮罩层 -->
    <div class="mask"></div>
    <!-- 下面才是在对话框中，真正显示的内容 -->
    <div class="new_build">
      <div class="build-top">
        <p>新建资料（仓库盘差）</p>
        <i class="el-icon-close" @click="closeNew_build"></i>
      </div>

      <div class="build-info">
        <div class="build-info-1">
          <p>盘差日期</p>
          <el-date-picker
            v-model="differTime"
            value-format="yyyy-MM-dd HH:mm:ss"
            type="date"
          >
          </el-date-picker>
          <p>单号</p>
          <el-input
            :disabled="Dis"
            v-model="receiptsNumber"
            class="build-inp"
          ></el-input>
          <p>仓库编号</p>
          <!-- <el-input :disabled="Dis" v-model="warehouseNo" class="build-inp"></el-input> -->
          <el-select :disabled="Dis" v-model="warehouseNo" class="build-inp">
            <el-option
              v-for="item in warehouseList"
              :key="item.value"
              :label="item.value"
              :value="item.value"
            >
              <span style="float:left">{{ item.value }}</span>
              <span style="float:right">{{ item.label }}</span>
            </el-option>
          </el-select>

          <p>盘差序号</p>
          <el-input v-model="sequence" disabled></el-input>
        </div>
        <div style="display:flex;margin:10px 0">
          <p
            style="display:inline-block;width:80px;text-align:right;margin-right:15px;"
          >
            售价
          </p>
          <el-input
            v-model="sellingPrice"
            disabled
            class="build-inp"
          ></el-input>
        </div>
        <!-- 下面是表格区域 -->
        <div class="build-info-4">
          <el-table
            border
            :data="codeData"
            id="codeTable"
            class="tb-edit"
            @cell-click="cellClick"
            style="width:100%;margin-bottom:20px"
            max-height="148px"
            :header-cell-style="{
              background: '#f4f4f4',
              padding: 0,
              height: '40px'
            }"
            :cell-style="{ padding: 0, height: '36px' }"
          >
            <!-- 这一列的header表示款号 -->
            <el-table-column :label="header"> </el-table-column>
            <el-table-column prop="colorName" label="颜色"> </el-table-column>
            <!-- <el-table-column
              prop="colorNo"
              label="颜色編號">
            </el-table-column> -->

            <!-- 如果你想让每一个表格都是可以输入的，那么就拿剩下的表格来进行遍历 -->
            <template v-for="col in sizeList">
              <el-table-column
                :key="col + Math.random()"
                :prop="col"
                :label="col"
              >
                <template slot-scope="scope">
                  <!-- <el-form :v-model="scope.row"> -->
                  <!-- <el-form-item> -->
                  <!-- <el-input v-model="scope.row[col]" @blur="handleClick(scope.$index,scope.row[col])" ></el-input>
                    <span>{{scope.row[col]}}</span> -->
                  <!-- </el-form-item> -->
                  <!-- </el-form> -->

                  <el-input
                    size="small"
                    class="innerInp"
                    v-model="scope.row[col]"
                    @blur="
                      handleClick($event, {
                        index: scope.$index,
                        key: col,
                        result: scope.row[col]
                      })
                    "
                    @keyup.enter.native="inpEnter"
                  >
                  </el-input>
                </template>
              </el-table-column>
            </template>
          </el-table>
        </div>
        <!-- 条码扫描区域 -->
        <div class="barcode">
          <p>条码扫描</p>
          <el-switch
            v-model="isBarcode"
            :disabled="isDis"
            active-color="#409EFF"
            inactive-color="#C0C4CC"
          >
          </el-switch>
          <!-- <el-radio :disabled="!isBarcode" v-model="radio" label="1">货号码</el-radio>
          <el-radio :disabled="!isBarcode" v-model="radio" label="2">ID码</el-radio> -->
          <i
            class="el-icon-question"
            style="color:#017aff;margin:4px 6px 0 15px;"
          ></i>
          <p>冲减单子. 点"款号"， 请按F7，把数量填成-1</p>
        </div>
        <!-- 扫描/输入条码,按回车键的区域 -->
        <div class="enterBarcode">
          <el-input
            @keyup.enter.native="scanning($event)"
            v-model="searchValue"
            placeholder="扫描/输入条码,按回车键"
            id="input"
          ></el-input>
          <p style="margin:15px 0 0 5px;">合计：{{ howMany }}</p>
        </div>
        <!-- 下面是大表格的区域 -->
        <el-table
          height="410px"
          :data="barcodeData"
          style="width: 100%"
          :header-cell-style="{
            background: '#f4f4f4',
            padding: 0,
            height: '40px'
          }"
          :cell-style="{ padding: 0, height: '36px' }"
          highlight-current-row
          @row-click="rowClick"
        >
          <el-table-column prop="sequence" label="仓库盘点序号" width="110px">
          </el-table-column>
          <el-table-column prop="receiptsNumber" label="单号">
          </el-table-column>
          <el-table-column prop="warehouseNo" label="仓库编号">
          </el-table-column>
          <el-table-column prop="kindsNumber" label="款号" width="145px">
          </el-table-column>
          <el-table-column prop="sellingPrice" label="售价" width="70px">
          </el-table-column>
          <el-table-column prop="differNumber" label="盘差数量">
          </el-table-column>
          <el-table-column prop="differMoney" label="盘差金额">
          </el-table-column>
          <el-table-column prop="differTime" label="盘差日期" width="100">
          </el-table-column>
          <el-table-column prop="curency" label="币种" width="50px">
          </el-table-column>
          <el-table-column prop="operator" label="操作员"> </el-table-column>
          <el-table-column prop="enteringTime" label="录入日期" width="90px">
          </el-table-column>
          <el-table-column prop="status" label="修改状态"> </el-table-column>
        </el-table>
      </div>
      <!-- 下面是底部按钮区域 -->
      <div class="build-btn">
        <div style="margin:5px 20px 0 0">
          <!-- <el-button @click="closeNew_build">取消</el-button> -->
          <el-button type="primary" plain @click="saveNew_build"
            >保存</el-button
          >
          <el-button type="primary" @click="keepGoing">继续录入</el-button>
        </div>
      </div>
    </div>

    <div class="popup" :style="{ display: showPopup }">
      <div class="popup_t">
        <p>输入扫描数量</p>
        <i
          class="el-icon-close"
          @click="
            () => {
              this.showPopup = 'none'
            }
          "
        ></i>
      </div>
      <div class="popup_c">
        <p>请输入扫描数量</p>
        <p>如果不输入则扫描数量为1</p>
        <el-input v-model="one" style="margin-top:10px"></el-input>
        <!-- <input type="text" v-model="one" class="popup_button"> -->
      </div>
      <div class="popup_b">
        <el-button
          @click="
            () => {
              this.showPopup = 'none'
            }
          "
          >取消</el-button
        >
        <el-button @click="preservation" type="primary">确定</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import {
  kindsNumberOutContinue,
  kindsNumberOut,
  getNumber
} from '../../../../network/customerOutTotal'
import { getWarehouse } from '../../../../network/warehouse'
import { getKindsNumberList } from '../../../../network/artNo'
import { getScanning, getBarCode } from '../../../../network/manufacturer'
import enterUp from '../../../../components/mixins/enterUp'
import today from '../../../../components/mixins/today'
export default {
  mixins: [enterUp, today],
  created() {
    this.differTime = this.getNowTime()
    this.inpList = this.getInput() //input enter移动
    //仓库编号
    getWarehouse().then(res => {
      // console.log(res.data.data)
      res.data.data.forEach(e => {
        this.warehouseList.push({
          label: e.name,
          value: e.no,
          Main: e.isMainWarehouse
        })
      })
      for (let a of res.data.data) {
        if (a.isMainWarehouse == 1) {
          this.warehouseNo = a.no //主仓库
        }
      }
    })
  },

  data() {
    return {
      howMany: '',
      inpList: [],
      warehouseList: [],
      Dis: false,
      isDis: false,
      deta: [],
      id: '',
      // isKindsNumber:false,
      // obj2:[],
      header: '款号',
      AAa: [],
      showPopup: 'none',
      differTime: '',
      receiptsNumber: '',
      warehouseNo: '', // 这个是仓库编号 ？？？
      one: 1,
      differMoney: '',
      sequence: '',
      sellingPrice: '',
      cols: ['7', '9', '1', '3', '5', '7', 'F'],
      isBarcode: false, // 条码扫描swith开关的状态
      // radio:'2',
      searchValue: '', // 扫描、输入条码框输入的值
      codeData: [], // 中间表格的数据
      barcodeData: [], // 底部大表格的数据
      XHList: [],
      XHList1: [],
      sizeList: [],
      barcodeData1: []
    }
  },
  methods: {
    sibling(e) {
      let s = []
      let pp = e.parentNode.parentNode.children
      // console.log(pp)
      // console.log(pp)
      for (let j = 0; j < pp.length; j++) {
        let p = pp[j].children
        for (let i = 0, pl = p.length; i < pl; i++) {
          if (p[i] !== e) s.push(p[i])
        }
      }
      return s
    },
    handleClick(e, { index, key, result }) {
      e.target.parentNode.parentNode.parentNode.classList.remove('activeCell')
      let r = /^(0|[1-9][0-9]*|-[1-9][0-9]*)$/
      if (result != 0) {
        result = result.replace(/\b(0+)/gi, '')
      }
      if (!r.test(result) && result) {
        this.$alert('数量请输入整数', '', {
          confirmButtonText: '确定'
        })
        this.codeData[index][key] = 0
        return
      }
      this.codeData[index][key] = result
    },
    cellClick(row, column, cell, event) {
      cell.classList.add('activeCell')
      let s = this.sibling(cell)
      // console.log(s)
      s.forEach(e => {
        e.classList.remove('activeCell')
      })
    },
    inpEnter(e) {
      e.target.parentNode.parentNode.parentNode.classList.remove('activeCell')
    },

    closeNew_build() {
      this.one = 1
      this.receiptsNumber = ''
      // this.warehouseNo = ''
      this.searchValue = ''
      this.barcodeData1 = []
      this.barcodeData = []
      this.isBarcode = false
      this.Dis = false
      this.isDis = false
      this.howMany = ''
      this.$emit('closeNew_build')
    },
    //保存数据
    saveNew_build() {
      if (!this.barcodeData.length) {
        this.$emit('closeNew_build')
        return
      }
      if (
        this.differTime == '' ||
        this.receiptsNumber == '' ||
        this.warehouseNo == ''
      ) {
        this.$message({
          type: 'error',
          message: '盘差日期，单号或仓库编号不能为空'
        })
        return
      }
      this.receiptsNumber = ''
      // this.warehouseNo = ''
      this.searchValue = ''
      this.isBarcode = false
      this.Dis = false
      this.isDis = false
      this.one = 1
      this.$emit('saveNew_build', this.barcodeData)
      this.howMany = ''
      this.barcodeData = []
      this.barcodeData1 = []
      this.Dis = false
    },

    //继续录入
    keepGoing() {
      // if(this.differTime == '' || this.receiptsNumber == ''|| this.warehouseNo == ''){
      //   this.$message({
      //     type: 'warning',
      //     message: '盘差日期，单号或仓库编号不能为空'
      //   });
      //   return
      //   }
      //   this.$emit("keepSave",this.barcodeData)
      //   this.searchValue = ''
      //   this.barcodeData = []
      // 点击继续录入的时候，这个用来判断日期不能为空
      if (this.differTime == '' || this.differTime == null) {
        this.$message.warning('日期不能为空')
      }
      if (!this.isBarcode) {
        // 点击继续录入的时候，条码扫描关闭的时候，触发这个函数
        this.continueInput()
        this.codeData = []
      } else {
        // 点击继续录入的时候，条码扫描开启的时候，触发这个函数（先不管这个）
        this.scanning()
      }
    },

    //条码扫描 (当条码输入框按下回车之后，触发这个函数)
    scanning() {
      // 条码扫描输入框是否填写了，如果填写了执行if语句
      if (this.searchValue) {
        if (!this.isBarcode) {
          // 输入框填写之后并且条码扫描是关闭的状态
          // console.log('条码扫描关')
          if (
            // 盘查日期不能为空，单号不能为空，仓库编号不能为空，receiptsNumber 单号
            this.differTime == '' ||
            this.receiptsNumber == '' ||
            this.warehouseNo == '' ||
            this.differTime == null
          ) {
            this.$message({
              type: 'error',
              message: '盘差日期，单号或仓库编号不能为空'
            })
            return
          }
          // 手输款号 （根据货号获取所有货号数组）, { kindsNumberStr: this.searchValue }就是一个普通的params参数对象，只是接口的时候，给了默认值，this.searchValue就是输入的款号，根据款号，获取所有的款号
          getKindsNumberList({ kindsNumberStr: this.searchValue }).then(res => {
            // console.log(res)
            this.XHList = res.data.data.data
            // console.log(this.XHList) // 这个是所有的数据
            if (res.data.data.data.length) {
              this.header = res.data.data.data[0].styleNumber // 如果有数据返回，那么就拿款号来当表单项
              this.$emit('inpNumChange') //按款号查出数据 输入框增多 inpNumChange传给父组件函数 再次获取 this.inpList = this.getInput() enter键跳下一个输入框
              // 品牌公司查条码规律详情
              getBarCode({
                company: res.data.data.data[0].brandedCompany
              }).then(res => {
                // console.log(res)
                this.manufacturerBarCode = res.data.data[0] // data[0]:[{id: 178, company: '郭氏', styleNumber: 5, colorNumber: 2, styleColor: 1, …}]
              })
              // console.log(this.manufacturerBarCode)
              // 输入款号显示中间表和尺码信息   ZZZ-AAS
              res.data.data.data.sort((a, b) => {
                return a.relevanceSize.localeCompare(b.relevanceSize)
              })

              // tmp就是所有数据数组
              let tmp = res.data.data.data
              this.tmpBarcodeData = tmp
              // console.log(tmp)

              // 中间表  尺码表头
              // console.log(tmp[0], 'ok')
              // console.log(tmp[1], 'ok1')
              // console.log(tmp[2], 'ok2')
              // console.log(tmp[0].size) // 9
              // console.log(tmp[1].size) // 9
              // console.log(tmp[2].size) // 9
              // console.log(tmp[3].size) // 9
              // console.log(tmp[4].size) // 1
              // console.log(tmp[5].size) // 1
              // console.log(tmp[6].size) // 1
              this.sizeList = [tmp[0].size] // 这个是显示整个表格尺码的数组
              let isExistSize = 0
              for (const i of tmp) {
                for (const j of this.sizeList) {
                  if (j == i.size) {
                    isExistSize = 0
                    break
                  }
                  isExistSize = 1
                }
                if (isExistSize) {
                  this.sizeList.push(i.size)
                  // console.log(this.sizeList)
                }
              }

              // 中间表
              let tmpCodeData = [
                { colorNo: tmp[0].colorNo, colorName: tmp[0].colorName }
              ]
              let isExistColor = 0
              for (const i of tmp) {
                for (const j of tmpCodeData) {
                  if (j.colorName == i.colorName) {
                    isExistColor = 0
                    break
                  }
                  isExistColor = 1
                }
                if (isExistColor) {
                  tmpCodeData.push({
                    colorNo: i.colorNo,
                    colorName: i.colorName
                  })
                }
              }
              tmpCodeData.forEach(e => {
                this.sizeList.forEach(f => {
                  e[f] = ''
                })
              })
              this.codeData = tmpCodeData // 在这里的时候，codeData就是中间表的数据
              let codeTable = document.getElementById('codeTable')
              let inputs = codeTable.getElementsByTagName('input')
              // console.log(inputs)
              let int = setInterval(() => {
                clearInterval(int)
                inputs[0].focus()
                inputs[inputs.length - 1].onkeyup = e => {
                  if (window.event.keyCode == 13) {
                    // keyCode==13代表enter回车键
                    this.continueInput()
                    this.codeData = []
                    inputs[inputs.length - 1].onkeyup = () => {}
                  }
                }
              }, 100)
            } else {
              // 没有数据返回来，那么就是没有这个款号
              this.$message('此货号/款号无数据')
              // this.$refs.barcodeInput.focus()
            }
          })
        } else {
          // 开条码扫描

          if (
            this.differTime == '' ||
            this.receiptsNumber == '' ||
            this.warehouseNo == ''
          ) {
            this.$message({
              type: 'warning',
              message: '盘差日期，单号或仓库编号不能为空'
            })
            return
          }
          //判断库存够不够
          let kindsNumberNumberMap = {}
          kindsNumberNumberMap[this.searchValue] = Number(this.one)
          // console.log(kindsNumberNumberMap)
          let obj3 = {
            companyNo: this.warehouseNo,
            kindsNumberNumberMap
          }
          getNumber(JSON.stringify(obj3)).then(res => {
            // console.log(res.data)
            if (res.data.code == 202) {
              this.$message.error({
                message: '查无此对象'
              })
              return
            }
            if (res.data.data == this.searchValue) {
              this.$message.error({
                message: '此货号库存不够'
              })
              return
            } else {
              var obj2 = {
                isKindsNumber: 1,
                searchValue: this.searchValue
                // isScanner:this.isBarcode //是否开启条码扫描
              }
              // console.log(obj2)
              getScanning(obj2).then(res => {
                this.isDis = true
                // this.barcodeData.push(JSON.stringify(res.data.data));
                // console.log(res.data)
                if (res.data.data == null) {
                  this.$message({
                    type: 'error',
                    message: '该货号没有数据'
                  })
                }
                this.AAa = res.data.data

                for (let e in this.AAa) {
                  this.differMoney = this.AAa[e].sellingPrice * this.one
                  delete this.AAa[e].id //删除id对象
                  this.AAa[e]['receiptsNumber'] = this.receiptsNumber
                  this.AAa[e]['warehouseNo'] = this.warehouseNo
                  this.AAa[e]['differTime'] = this.differTime //改为标准日期
                  this.AAa[e]['differNumber'] = this.one
                  this.AAa[e]['differMoney'] = this.differMoney
                  this.AAa[e]['curency'] = '￥'
                  this.AAa[e]['status'] = 0
                  this.AAa[e]['dataSource'] = this.radio == '1' ? 1 : 0
                  this.Dis = true
                }

                if (this.barcodeData == '') {
                  this.barcodeData = this.AAa
                } else {
                  this.merge(this.barcodeData, this.AAa)
                  // this.AAa为一条数据 两组数据比较 this.barcodeData数组对象里的kindsNumber与this.AAa数组对象里的kindsNumber一样 sum 就相加 else 就push进this.barcodeData
                }
                // console.log(this.barcodeData)

                this.howMany = this.barcodeData.reduce((prev, next) => {
                  return prev + next.differNumber
                }, 0)
                // console.log(this.barcodeData)
                this.searchValue = ''
                document.getElementById('input').focus()
              })
            }
          })
        }
      }
      // console.log(document.getElementsByTagName('input'))
    },

    merge(target, source) {
      const targetIds = target.reduce(
        (res, v) => res.add(v.kindsNumber),
        new Set()
      )
      const sourceIds = source.reduce(
        (res, v) => res.add(v.kindsNumber),
        new Set()
      )
      target.forEach(v => sourceIds.has(v.kindsNumber) && v.differNumber++)
      return target.push(...source.filter(v => !targetIds.has(v.kindsNumber)))
    },

    aka() {
      //数组对象里 customerNo相同  数量相加 合并
      var tmp = {} //
      for (let u in this.barcodeData1) {
        var key = this.barcodeData1[u].kindsNumber
        if (tmp[key]) {
          tmp[key].kindsNumber = this.barcodeData1[u].kindsNumber
          tmp[key].differNumber += Number(this.barcodeData1[u].differNumber)
          tmp[key].curency = this.barcodeData1[u].curency
          tmp[key].differMoney = this.barcodeData1[u].differMoney
          tmp[key].differTime = this.barcodeData1[u].differTime
          tmp[key].warehouseNo = this.barcodeData1[u].warehouseNo
          tmp[key].receiptsNumber = this.barcodeData1[u].receiptsNumber

          tmp[key].waveBand = this.barcodeData1[u].waveBand
          tmp[key].vipPrice = this.barcodeData1[u].vipPrice
          tmp[key].supplier = this.barcodeData1[u].supplier
          tmp[key].styleNumber = this.barcodeData1[u].styleNumber
          tmp[key].status = this.barcodeData1[u].status
          tmp[key].statistics = this.barcodeData1[u].statistics
          tmp[key].splitNumber = this.barcodeData1[u].splitNumber
          tmp[key].softwareCustomerId = this.barcodeData1[u].softwareCustomerId
          tmp[key].sizeNo = this.barcodeData1[u].sizeNo
          tmp[key].sizeKind = this.barcodeData1[u].sizeKind
          tmp[key].size = this.barcodeData1[u].size
          tmp[key].sellingPriceTwo = this.barcodeData1[u].sellingPriceTwo
          tmp[key].sellingPriceThree = this.barcodeData1[u].sellingPriceThree
          tmp[key].sellingPriceOne = this.barcodeData1[u].sellingPriceOne
          tmp[key].sellingPriceFour = this.barcodeData1[u].sellingPriceFour
          tmp[key].sellingPrice = this.barcodeData1[u].sellingPrice
          tmp[key].relevanceSize = this.barcodeData1[u].relevanceSize
          tmp[key].quarter = this.barcodeData1[u].quarter
          tmp[key].originalManufacturerKindsNumber = this.barcodeData1[
            u
          ].originalManufacturerKindsNumber
          tmp[key].originalKindsNumber = this.barcodeData1[
            u
          ].originalKindsNumber
          tmp[key].onePrice = this.barcodeData1[u].onePrice
          tmp[key].newSize = this.barcodeData1[u].newSize
          tmp[key].newKindsNumber = this.barcodeData1[u].newKindsNumber
          tmp[key].mnemonicCode = this.barcodeData1[u].mnemonicCode
          tmp[key].matchStyle = this.barcodeData1[u].matchStyle
          tmp[key].manufacturerType = this.barcodeData1[u].manufacturerType
          tmp[key].manufacturerPrice = this.barcodeData1[u].manufacturerPrice
          tmp[key].kindSort = this.barcodeData1[u].kindSort
          tmp[key].image = this.barcodeData1[u].image
          tmp[key].id = this.barcodeData1[u].id
          tmp[key].generalizePrice = this.barcodeData1[u].generalizePrice
          tmp[key].discount = this.barcodeData1[u].discount
          tmp[key].differentiateCondition = this.barcodeData1[
            u
          ].differentiateCondition
          tmp[key].costTwo = this.barcodeData1[u].costTwo
          tmp[key].costOne = this.barcodeData1[u].costOne
          tmp[key].commodityType = this.barcodeData1[u].commodityType
          tmp[key].commodityName = this.barcodeData1[u].commodityName
          tmp[key].colorNo = this.barcodeData1[u].colorNo
          tmp[key].colorName = this.barcodeData1[u].colorName
          tmp[key].brandedName = this.barcodeData1[u].brandedName
          tmp[key].brandedCompany = this.barcodeData1[u].brandedCompany
          tmp[key].accessoryName = this.barcodeData1[u].accessoryName
        } else {
          tmp[key] = {}
          tmp[key].kindsNumber = this.barcodeData1[u].kindsNumber
          tmp[key].differNumber = Number(this.barcodeData1[u].differNumber)
          tmp[key].curency = this.barcodeData1[u].curency
          tmp[key].differMoney = this.barcodeData1[u].differMoney
          tmp[key].differTime = this.barcodeData1[u].differTime
          tmp[key].warehouseNo = this.barcodeData1[u].warehouseNo
          tmp[key].receiptsNumber = this.barcodeData1[u].receiptsNumber

          tmp[key].waveBand = this.barcodeData1[u].waveBand
          tmp[key].vipPrice = this.barcodeData1[u].vipPrice
          tmp[key].supplier = this.barcodeData1[u].supplier
          tmp[key].styleNumber = this.barcodeData1[u].styleNumber
          tmp[key].status = this.barcodeData1[u].status
          tmp[key].statistics = this.barcodeData1[u].statistics
          tmp[key].splitNumber = this.barcodeData1[u].splitNumber
          tmp[key].softwareCustomerId = this.barcodeData1[u].softwareCustomerId
          tmp[key].sizeNo = this.barcodeData1[u].sizeNo
          tmp[key].sizeKind = this.barcodeData1[u].sizeKind
          tmp[key].size = this.barcodeData1[u].size
          tmp[key].sellingPriceTwo = this.barcodeData1[u].sellingPriceTwo
          tmp[key].sellingPriceThree = this.barcodeData1[u].sellingPriceThree
          tmp[key].sellingPriceOne = this.barcodeData1[u].sellingPriceOne
          tmp[key].sellingPriceFour = this.barcodeData1[u].sellingPriceFour
          tmp[key].sellingPrice = this.barcodeData1[u].sellingPrice
          tmp[key].relevanceSize = this.barcodeData1[u].relevanceSize
          tmp[key].quarter = this.barcodeData1[u].quarter
          tmp[key].originalManufacturerKindsNumber = this.barcodeData1[
            u
          ].originalManufacturerKindsNumber
          tmp[key].originalKindsNumber = this.barcodeData1[
            u
          ].originalKindsNumber
          tmp[key].onePrice = this.barcodeData1[u].onePrice
          tmp[key].newSize = this.barcodeData1[u].newSize
          tmp[key].newKindsNumber = this.barcodeData1[u].newKindsNumber
          tmp[key].mnemonicCode = this.barcodeData1[u].mnemonicCode
          tmp[key].matchStyle = this.barcodeData1[u].matchStyle
          tmp[key].manufacturerType = this.barcodeData1[u].manufacturerType
          tmp[key].manufacturerPrice = this.barcodeData1[u].manufacturerPrice
          tmp[key].kindSort = this.barcodeData1[u].kindSort
          tmp[key].image = this.barcodeData1[u].image
          tmp[key].id = this.barcodeData1[u].id
          tmp[key].generalizePrice = this.barcodeData1[u].generalizePrice
          tmp[key].discount = this.barcodeData1[u].discount
          tmp[key].differentiateCondition = this.barcodeData1[
            u
          ].differentiateCondition
          tmp[key].costTwo = this.barcodeData1[u].costTwo
          tmp[key].costOne = this.barcodeData1[u].costOne
          tmp[key].commodityType = this.barcodeData1[u].commodityType
          tmp[key].commodityName = this.barcodeData1[u].commodityName
          tmp[key].colorNo = this.barcodeData1[u].colorNo
          tmp[key].colorName = this.barcodeData1[u].colorName
          tmp[key].brandedName = this.barcodeData1[u].brandedName
          tmp[key].brandedCompany = this.barcodeData1[u].brandedCompany
          tmp[key].accessoryName = this.barcodeData1[u].accessoryName
        }
      }
      // barcodeData主要是接受tmp的每一项弄成数组
      this.barcodeData = []
      for (let k in tmp) {
        this.barcodeData.push(tmp[k])
      }
      // console.log(this.barcodeData)
    },
    // 继续录入并且条码扫描关闭的时候，执行
    continueInput() {
      // 仓库编号为空，直接return
      if (!this.warehouseNo) {
        this.$message({
          type: 'warning',
          message: '仓库不能为空'
        })
        return
      }

      let isNew = false
      let kindsNumberNumMap = {}

      if (this.isBarcode) {
        // 如果用户开启了条码扫描，下面逻辑全部被注释掉，如果开启swith，那么if不做判断，直接跳过
        // 扫描
        // this.radio被注释，if和else if不再执行
        // if (this.radio == 1) {
        //   // 扫描货号码
        //   kindsNumberNumMap[this.searchValue] = this.scanNum
        // } else if (this.radio == 2) {
        //   // 扫描ID码
        //   searchKindsNumber({
        //     // 条码与货号是否一致
        //     isSame: false,
        //     // 是否开启条码扫描
        //     isScanner: true,
        //     searchValue: this.searchValue
        //   }).then(res => {
        //     console.log(res)
        //     kindsNumberNumMap[res.data.data[0].kindsNumber] = this.scanNum
        //   })
        // }
      } else {
        // 如果用户关闭条码扫描的话，走下面的逻辑
        // 输入
        let knList = []
        // console.log(this.codeData) // 打印的是表格里面输入的键值对
        this.codeData.forEach(e => {
          // e 就是item
          let c = e.colorNo
          this.sizeList.forEach(f => {
            if (this.manufacturerBarCode.styleColorSize) {
              // 型尺色

              if (this.manufacturerBarCode.styleColor) {
                // 款号与尺码之间有 -

                if (this.manufacturerBarCode.colorSize) {
                  // 色号与尺码之间有 -
                  knList.push({
                    kindsNumber: `${this.header}-${f}-${c}`,
                    sum: e[f]
                  })
                } else {
                  // 色号与尺码之间没有 -
                  knList.push({
                    kindsNumber: `${this.header}-${f}${c}`,
                    sum: e[f]
                  })
                }
              } else {
                // 款号与尺码之间没有 -

                if (this.manufacturerBarCode.colorSize) {
                  // 色号与尺码之间有 -
                  knList.push({
                    kindsNumber: `${this.header}${f}-${c}`,
                    sum: e[f]
                  })
                } else {
                  // 色号与尺码之间没有 -
                  knList.push({
                    kindsNumber: `${this.header}${f}${c}`,
                    sum: e[f]
                  })
                }
              }
            } else {
              // 型色尺

              if (this.manufacturerBarCode.styleColor) {
                // 款号与颜色之间有 -

                if (this.manufacturerBarCode.colorSize) {
                  // 色号与尺码之间有 -
                  knList.push({
                    kindsNumber: `${this.header}-${c}-${f}`,
                    sum: e[f]
                  })
                } else {
                  // 色号与尺码之间没有 -
                  knList.push({
                    kindsNumber: `${this.header}-${c}${f}`,
                    sum: e[f]
                  })
                }
              } else {
                // 款号与颜色之间没有 -

                if (this.manufacturerBarCode.colorSize) {
                  // 色号与尺码之间有 -
                  knList.push({
                    kindsNumber: `${this.header}${c}-${f}`,
                    sum: e[f]
                  })
                } else {
                  // 色号与尺码之间没有 -
                  knList.push({
                    kindsNumber: `${this.header}${c}${f}`,
                    sum: e[f]
                  })
                }
              }
            }
          })
        })
        // console.log(knList)
        this.XHList1 = knList
        var kindList = {}
        knList.forEach(e => {
          if (e.sum != '') {
            kindList[e.kindsNumber] = e.sum
          }
        })
        // console.log(kindList)
      }

      //判断库存够不够
      let kindsNumberNumberMap = kindList
      let obj3 = {
        companyNo: this.warehouseNo,
        kindsNumberNumberMap
      }
      getNumber(JSON.stringify(obj3)).then(res => {
        // console.log(res.data)
        if (res.data.code == 202) {
          this.$message.error({
            message: '查无此对象'
          })
          return
        }
        for (var g in this.XHList1) {
          for (let k in res.data.data) {
            if (
              this.XHList1[g].kindsNumber == res.data.data[k] ||
              this.XHList1[g].sum == ''
            ) {
              this.$message.error({
                message: `${res.data.data}'货号库存不够'`
              })
              this.XHList1.splice(g, 1)
              // console.log(this.XHList1)
            }
          }
        }
        // console.log(this.XHList1)
        for (let a in this.XHList1) {
          for (let b in this.XHList) {
            if (
              this.XHList1[a].kindsNumber == this.XHList[b].kindsNumber &&
              this.XHList1[a].sum != ''
            ) {
              this.XHList[b]['differNumber'] = this.XHList1[a].sum
              this.XHList[b]['differMoney'] =
                Number(this.XHList[b].differNumber) *
                Number(this.XHList[b].sellingPrice)
              this.XHList[b]['receiptsNumber'] = this.receiptsNumber
              this.XHList[b]['warehouseNo'] = this.warehouseNo
              this.XHList[b]['differTime'] = this.differTime //改为标准日期
              this.XHList[b]['curency'] = '￥'
              // this.AAa[w]["status"] = 0;
              this.barcodeData1.push(this.XHList[b])
              // console.log(this.barcodeData1)
            }
            this.aka()
          }
        }
        this.howMany = this.barcodeData.reduce((prev, next) => {
          return prev + next.differNumber
        }, 0)
      })
    },

    rowClick(e) {
      this.deta = e
      this.id = e.id
      // console.log(this.deta)
      // console.log(e.id)
    },

    //7改数量
    preservation() {
      this.showPopup = 'none'
      this.$message({
        type: 'success',
        message: '数量设置成功'
      })
      // console.log(this.barcodeData)
    }
  },
  mounted() {
    let _this = this
    document.onkeydown = function(event) {
      let e = event || window.event || arguments.callee.caller.arguments[0]
      if (e && e.keyCode == 118) {
        // 按 F7
        // console.log("ffffffffff")
        if (_this.showPopup == 'none') {
          _this.showPopup = 'block'
        } else {
          _this.showPopup = 'none'
        }
      }
    }
  },
  watch: {
    receiptsNumber(a, b) {
      if (a) {
        this.receiptsNumber = a.toUpperCase().trim()
      }
    },
    searchValue(a, b) {
      if (a) {
        this.searchValue = a.toUpperCase().trim()
      }
    }
  }
}
</script>

<style scoped>
.middle {
  padding: 10px 15px;
}
.middle p {
  padding-bottom: 10px;
}
._top {
  display: flex;
  width: 100%;
  height: 40px;
  padding: 10px 15px;
  justify-content: space-between;
  background: #f8f8f8;
  font-weight: 700;
}

/* 新建资料 */
.mask {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: #000;
  opacity: 0.3;
  z-index: 9;
}
.new_build {
  position: fixed;
  /* position: relative; */
  top: 5%;
  left: 50%;
  transform: translateX(-50%);
  width: 1100px;
  height: 90%;
  z-index: 99;
  background-color: white;
  overflow: auto;
}
.new_build .build-top {
  height: 40px;
  background-color: #f8f8f8;
  display: flex;
  justify-content: space-between;
  padding: 10px 15px;
}
.build-top p {
  font-weight: 700;
}

.new_build input {
  height: 30px;
  border: 1px solid #dcdfe6;
  border-radius: 5px;
  margin-left: 10px;
}
.new_build input:focus {
  outline: none;
  border: 1px solid #409eff;
}

.build-info {
  padding: 0 15px;
  padding-bottom: 10px;
  /* border-bottom: buildlid #f2f2f2 2px; */
}
.build-info-1 p {
  display: inline-block;
  width: 80px;
  text-align: right;
  margin-right: 15px;
}

.barcode {
  display: flex;
}

.build-info .barcode p {
  display: inline;
  margin-right: 15px;
}
.build-info .barcode div {
  margin-top: 15px;
}

.barcode-info-1 p,
.barcode-info-2 p {
  display: inline-block;
  width: 96px;
  text-align: right;
  margin-right: 9px;
}

.colorBox,
.infoBox {
  display: inline;
}

.enterBarcode {
  display: flex;
  height: 60px;
  background-color: #f2f2f2;
  margin: 15px 0;
}

.build-btn {
  text-align: right;
}
.po {
  left: 0;
  right: 0;
  position: absolute;
  opacity: 0;
  z-index: 0;
}
.popup {
  width: 400px;
  height: 200px;
  border: 1px solid #dbdbdb;
  box-shadow: 0 2px 2px 2px #dbdbdb;
  z-index: 999;
  position: absolute;
  left: 30%;
  top: 20%;
  /* margin:-100px 0 0 -200px; */
  background: white;
  /* display: block; */
}
.popup_t {
  display: flex;
  justify-content: space-between;
  width: 100%;
  height: 40px;
  background: rgb(244, 244, 244);
  padding: 8px 15px;
}
.popup_t p {
  font-weight: 700;
}
.popup_c {
  padding: 8px 15px;
}
.popup_button {
  margin: 5px 0 0 0;
  width: 94%;
  height: 30px;
  padding: 0 10px;
  border: 1px solid #dbdbdb;
  border-radius: 3px;
}
.popup_button:focus {
  outline: none;
  border: 1px solid #017fff;
}
.popup_b {
  margin: 10px 0 0 0;
  padding-left: 230px;
}
.build-inp {
  width: 160px;
}
</style>

<style>
.new_build .build-info-4 .el-table .cell {
  box-sizing: border-box;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal;
  word-break: break-all;
  line-height: 41px;
  padding-right: 10px;
  height: 40px;
}
.new_build .build-info-4 .el-input__inner {
  border: 0px;
}
.new_build .build-info-4 .el-input__inner:focus {
  border: 1px solid #017aff;
}

/* .new_build .build-info-1 .el-input, .new_build .build-info-3 .el-input{
    width: 425px;
  } */
.new_build .build-info-1 .el-input,
.new_build .build-info-2 .el-input {
  margin-top: 10px;
  width: 160px;
}
.new_build .el-input__inner {
  height: 30px !important;
}
.new_build .el-input__icon {
  line-height: 30px !important;
}
.build-info .barcode .el-switch {
  margin: 0 !important;
}

.new_build .enterBarcode .el-input {
  width: 535px;
  margin: 14px 17px;
}
.new_build .barcode .el-radio {
  margin: 5px 5px 0 20px;
}
</style>
